package csc.fresher.finalgroupfour.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import csc.fresher.finalgroupfour.dao.AccountDAO;
import csc.fresher.finalgroupfour.dao.CustomerDAO;
import csc.fresher.finalgroupfour.dao.RoleDAO;
import csc.fresher.finalgroupfour.dao.StateDAO;
import csc.fresher.finalgroupfour.dao.TransactionDAO;
import csc.fresher.finalgroupfour.dao.UserDAO;
import csc.fresher.finalgroupfour.domain.Account;
import csc.fresher.finalgroupfour.domain.Customer;
import csc.fresher.finalgroupfour.domain.Role;
import csc.fresher.finalgroupfour.domain.State;
import csc.fresher.finalgroupfour.domain.Transaction;
import csc.fresher.finalgroupfour.domain.User;

/**
 * A class that provides functions to call DAO's functions.
 * @author CSCADMIN
 *
 */
@Service
public class BankService {
	@Autowired
	private AccountDAO accountDAO;
	@Autowired
	private CustomerDAO customerDAO;
	@Autowired
	private RoleDAO roleDAO;
	@Autowired
	private StateDAO stateDAO;
	@Autowired
	private TransactionDAO transactionDAO;
	@Autowired
	private UserDAO userDAO;
	
	//----------ACCOUNT SERVICE----------
	//
	//-----------------------------------
	public void addAccount(Account account) {
		accountDAO.addAccount(account);
	}
	public List<Account> listAccounts() {
		return accountDAO.listAccounts();
	}
	public void updateAccount(Account account) {
		accountDAO.updateAccount(account);
	}
	public void deleteAccount(Account account) {
		accountDAO.deleteAccount(account);
	}
	public List<Account> findAccounts(Customer customer) {
		return accountDAO.findAccounts(customer);
	}
	
	//----------CUSTOMER SERVICE----------
	//
	// -----------------------------------
	public void addCustomer(Customer customer) {
		customerDAO.addCustomer(customer);
	}

	public List<Customer> listCustomers() {
		return customerDAO.listCustomers();
	}
	
	public List<Customer> listAvailableCustomers() {
		return customerDAO.listAvailableCustomers();
	}

	public void updateCustomer(Customer customer) {
		customerDAO.updateCustomer(customer);
	}

	public void deleteCustomer(Customer customer) {
		customerDAO.deleteCustomer(customer);
	}

	public Customer findCustomer(String customerCardNumberId) {
		return customerDAO.findCustomer(customerCardNumberId);
	}
	
	//----------ROLE SERVICE----------
	//
	// -------------------------------
	public void addRole(Role role) {
		roleDAO.addRole(role);
	}

	public List<Role> listRoles() {
		return roleDAO.listRoles();
	}

	public void updateRole(Role role) {
		roleDAO.updateRole(role);
	}

	public void deleteRole(Role role) {
		roleDAO.deleteRole(role);
	}

	public boolean findRole(Role role) {
		return roleDAO.findRole(role);
	}
	
	//----------STATE SERVICE----------
	//
	// --------------------------------
	public void addState(State state) {
		stateDAO.addState(state);
	}

	public List<State> listStates() {
		return stateDAO.listStates();
	}

	public void updateState(State state) {
		stateDAO.updateState(state);
	}

	public void deleteState(State state) {
		stateDAO.deleteState(state);
	}

	public boolean findState(State state) {
		return stateDAO.findState(state);
	}
	
	//----------TRANSACTION SERVICE----------
	//
	// --------------------------------------
	public void addTransaction(Transaction transaction) {
		transactionDAO.addTransaction(transaction);
	}

	public List<Transaction> listTransactions() {
		return transactionDAO.listTransactions();
	}

	public void updateTransaction(Transaction transaction) {
		transactionDAO.updateTransaction(transaction);
	}

	public void deleteState(Transaction transaction) {
		transactionDAO.deleteTransaction(transaction);
	}

	public boolean findTransaction(Transaction transaction) {
		return transactionDAO.findTransaction(transaction);
	}
	
	//----------USER SERVICE----------
	//
	// -------------------------------
	public void addUser(User user) {
		userDAO.addUser(user);
	}

	public List<User> listUsers() {
		return userDAO.listUsers();
	}

	public void updateUser(User user) {
		userDAO.updateUser(user);
	}

	public void deleteState(User user) {
		userDAO.deleteUser(user);
	}

	public boolean findTransaction(User user) {
		return userDAO.findUser(user);
	}
	
	public boolean checkLogin(String loginId, String password){
		return userDAO.checkLogin(loginId, password);
	}
	public User findUser(String loginId) {
		// TODO Auto-generated method stub
		return userDAO.findUser(loginId);
	}
	public List<GrantedAuthority> getAuthorities(User user) {
		// TODO Auto-generated method stub
		return userDAO.getAuthorities(user);
	}
}
